//
//  PEMMotionMeInvitedCell.swift
//  RelationshipIntegration
//
//  Created by iOS-Czz on 2023/11/16.
//

import UIKit

class PEMMotionMeInvitedCell: UITableViewCell {
    var refreshBlock: (() -> Void)?
    @IBOutlet var nameLabel: UILabel!
    @IBOutlet var dateLabel: UILabel!
    @IBOutlet var timeLabel: UILabel!
    
    @IBOutlet var cancelButton: UIButton!
    @IBOutlet var locationLabel: UILabel!
    @IBOutlet var inviterLabel: UILabel!
    @IBOutlet var topLabel: UILabel!

    @IBOutlet var statusLabel: UILabel!
    @IBOutlet var completedButton: UIButton!
    @IBOutlet var bgView: UIView!
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    var model: PEMMotionCongruenceModel? {
        didSet {
            self.nameLabel.text = model?.name
            self.dateLabel.text = model?.date
            self.timeLabel.text = model?.time
            self.inviterLabel.text = "Invited: " + model!.inviter
            self.locationLabel.text = "Invitation location: " + model!.location
            if model!.completed || model!.canceled {
                self.cancelButton.isHidden = true
                self.completedButton.isHidden = true
                self.statusLabel.isHidden = false
                self.statusLabel.text = model!.completed ? "Completed":"Canceled"
            }else{
                self.cancelButton.isHidden = false
                self.completedButton.isHidden = false
                self.statusLabel.isHidden = true
            }
            self.topLabel.text = model!.completed ? "Completed" : "To be completed"
        }
    }
    @IBAction func clickCancelAction(_ sender: Any) {
        self.model?.canceled = true
        self.model?.updateToDB()
        self.refreshBlock?()
    }
    @IBAction func clickCompletedAction(_ sender: Any) {
        self.model?.completed = true
        self.model?.updateToDB()
        self.refreshBlock?()
    }
}
